package com.imooc.news_manager_project.config;

import com.imooc.news_manager_project.interceptor.RedisInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public RedisInterceptor authRedisInterceptor() {
        return new RedisInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authRedisInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/login/index")
                // 放开拦截器对于swagger2的拦截
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/v2/**")
                .excludePathPatterns("/user/lists")
                .excludePathPatterns("/swagger-ui.html/**");
    }
}
